package yunhe.servlet;

import yunhe.entity.AdminInfo;
import yunhe.service.AdminServers;
import yunhe.service.impl.AdminServersImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;


@SuppressWarnings("serial")
public class AdminLogin extends HttpServlet {



	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		String name=request.getParameter("loginId");
		String pass=request.getParameter("password");
		AdminServers asv=new AdminServersImpl();
		HttpSession session=request.getSession();
		AdminInfo re=asv.login(name, pass);
		if(re!=null){
			session.setAttribute("adminInfo", re);
			session.setAttribute("loginState", true);
			response.sendRedirect("mainform.jsp");
		}
		else{	
			session.setAttribute("loginState", false);
			response.sendRedirect("index.jsp");		
		}
	}


	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
